package com.kf.lib_imageload.imageutils
import android.widget.ImageView
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.kf.lib_imageload.imageload_sdk.GlideApp
import com.kf.lib_widget.R

const val LOAD_TYPE_TILE = 0 //平铺图片
const val LOAD_TYPE_ZOOM = 1 //缩略图
const val LOAD_TYPE_CIRCLE = 2 //头像圆形
const val LOAD_TYPE_CIRCLE_CORNER = 3 //圆角

class LoadImageUtils {

    fun loadImage(type: Int = LOAD_TYPE_TILE, image: ImageView, url: String) {
        when (type) {
            LOAD_TYPE_TILE -> {
                GlideApp.with(image.context)
                    .load(url)
                    .placeholder(R.mipmap.ic_launcher)
                    .error(R.mipmap.ic_launcher)
                    .into(image)
            }
            LOAD_TYPE_ZOOM -> {

            }
            LOAD_TYPE_CIRCLE_CORNER -> {
                GlideApp.with(image.context)
                    .load(url)
                    .error(R.mipmap.ic_launcher_round)
                    .placeholder(R.mipmap.ic_launcher_round)
                    .transform(RoundedCorners(20))
                    .into(image)
            }
            LOAD_TYPE_CIRCLE -> {
                GlideApp.with(image.context)
                    .load(url)
                    .error(R.mipmap.ic_launcher_round)
                    .placeholder(R.mipmap.ic_launcher_round)
                    .transform(CircleCrop())
                    .into(image)
            }
        }
    }

}